package design_4_builder.demo1.builder;


import java.util.Arrays;

public class StringBuilder extends AbstractStringBuilder {


	public StringBuilder() {
		super(16);
	}

	public StringBuilder(int capacity) {
		super(capacity);
	}


	@Override
	public synchronized StringBuilder append(String str) {
		super.append(str);
		return this;
	}

	@Override
	public synchronized StringBuilder append(char str) {
		super.append(str);
		return this;
	}

	@Override
	public synchronized StringBuilder append(boolean b) {
		super.append(b);
		return this;
	}


	//
	private transient char[] toStringCache;

	@Override
	public synchronized String toString() {
		if (toStringCache == null) {
			toStringCache = Arrays.copyOfRange(value, 0, count);
		}
		return new String(toStringCache);
	}
}
